<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>节目单列表页</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/WdatePicker/skin/WdatePicker.css">
<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"	src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/js/WdatePicker/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/lang/zh-cn/zh-cn.js"></script>

<link href="css/tscss.css" rel="stylesheet" type="text/css" /> 
<link href="css/smsstyle.css" rel="stylesheet" type="text/css" />
<link href="css/bmasdo2.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
	document.onkeydown = function(event) {
		var e = event || window.event || arguments.callee.caller.arguments[0];
		if (e && e.keyCode == 13) { // enter 键
			try {
				searchData();
			} catch (e) {
				gotoSearch($('#easyui-treegrid'));
			}
		}
	};
</script>
<style type="text/css">
.imgsw {
	background: url(../resource/images/a0133.png) no-repeat;
	height: 14px;
	width: 17px;
	display: inline-block;
	border: 0;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%
	String f_vc_id = request.getParameter("f_vc_id");
	String offAirTime = request.getParameter("offAirTime");

%>
</head>
<body>
<input name="f_vc_customid" id="f_vc_customid" value="-1" style="width: 140px;" type='hidden' />
<input name="f_vc_customName" id="f_vc_customName" style="width: 140px;" value="" type='hidden'/>

<div id="carousel_one">
	<%-- <jsp:include page="custom_select.jsp"/> --%>
	<table id="carousel" width="99%" border="0" cellspacing="0" cellpadding="3" align="center" class="tablex">
	   <tr>
	   <td colspan="5" height="25" valign="middle" align="center" class="OperateTitle" bgcolor="#DEDFDE">节目列表</td>
	   </tr>
	   <tr>
	   <td colspan="5" style="text-align:center"><input id="bt1" type="button" value="返回" onClick="back();" class="xbuton2">&nbsp;</td>
	   </tr>
		<tr>
	         <th align="center" style="width:15%">开播时间</th>
	         <th align="center" style="width:15%">停播时间</th>
	         <th align="center" style="width:30%">素材名称</th>
		 </tr>
		 
	</table>
</div>

	<table id=selectOffAirTime width="99%" border="0" cellspacing="0" cellpadding="3" align="center" class="tablex">
	   <tr>
	   <td colspan="5" height="25" valign="middle" align="center" class="OperateTitle" bgcolor="#DEDFDE">选择时间段停播</td>
	   </tr>
	   <tr>
	   <td colspan="5" style="text-align:center"><input id="bt1" type="button" value="返回" onClick="back_one();" class="xbuton2">&nbsp;</td>
	   </tr>
		<tr>
	         <th align="center" style="width:15%">选择</th>
	         <th align="center" style="width:15%">停播时间</th>
	         <th align="center" style="width:30%">素材名称</th>
		 </tr>
		 
	</table>

<script>
var f_vc_id = "<%=f_vc_id%>";
var offAirTime = "<%=offAirTime%>";
function viewMateral(){
	$.ajax({
	//	url:"../../virtual_channel/select_channel_material.do?f_vc_id="+f_vc_id,
		url:"../../virtual_channel/select_material.do?f_vc_id="+f_vc_id,
		success:function(data) {
			data = JSON.parse(data);
			var f_vc_airTime = data.f_vc_airTime;//00:00:00
			var f_vc_offAirTime = data.f_vc_offAirTime;//24:00:00
			var vcmList = data.virtualChannelMaterialVos;//可得到播放时长，时间秒数，素材信息
			var offAirTimes = f_vc_offAirTime.split(":");//结束时间
			var airTimes = f_vc_airTime.split(":");//开始时间
			var time = 0;//时长
			var str = '';
			var flag = 1;
			
			var vcList = data.interCutvirtualChannelVos;//插播节目列表
			var cbAirTime = null;//插播开始时间
			for(var i=0;i<vcmList.length;i++){
				time = vcmList[i].f_vcm_duration;
					for(var j=0;j<vcList.length;j++){
						cbAirTime = vcList[j].f_vc_airTime.split(":");//插播开始时间
						var vcmCBList = vcList[j].virtualChannelMaterialVos;//插播素材信息
						var cbTime = vcmCBList[0].f_vcm_duration;
						if(getS(cbAirTime)==getS(airTimes)){//正常插播
							for(var k=0;k<vcmCBList.length;k++){
								cbTime = vcmCBList[k].f_vcm_duration;
								str += '<tr>';
								str += '<td align="center">'+getHMS(getS(cbAirTime))+'</td>';
								str += '<td align="center">'+getHMS(getS(cbAirTime)+cbTime)+'</td>';
								str += '<td align="center">'+vcmCBList[k].f_vcm_materialName;
								str += '<font  color="#FF0000">&nbsp;（插播节目 ） </font></td>';
								str += '</tr>';
								cbAirTime = getHMS(getS(cbAirTime)+cbTime).split(":");
								airTimes = cbAirTime;
							}
						}else if(getS(cbAirTime)>getS(airTimes)&&getS(cbAirTime)<(getS(airTimes)+time)){
							str += '<tr>';
							str += '<td align="center">'+getHMS(getS(airTimes))+'</td>';
							str += '<td align="center">'+getHMS(getS(cbAirTime))+'</td>';
							str += '<td align="center">'+vcmList[i].f_vcm_materialName;
							str += '<font  color="#FF0000">&nbsp;（该片将被强行结束 ） </font></td>';
							str += '</tr>';
							for(var k=0;k<vcmCBList.length;k++){
								cbTime = vcmCBList[k].f_vcm_duration;
								str += '<tr>';
								str += '<td align="center">'+getHMS(getS(cbAirTime))+'</td>';
								str += '<td align="center">'+getHMS(getS(cbAirTime)+cbTime)+'</td>';
								str += '<td align="center">'+vcmCBList[k].f_vcm_materialName;
								str += '<font  color="#FF0000">&nbsp;（插播节目 ） </font></td>';
								str += '</tr>';
								cbAirTime = getHMS(getS(cbAirTime)+cbTime).split(":");
								airTimes = cbAirTime;
							}
						}
					}
					
				if(getS(airTimes)+time>=getS(offAirTimes)){//大于结束时间
					str += '<tr>';
					str += '<td align="center">'+getHMS(getS(airTimes))+'</td>';
					str += '<td align="center">'+getHMS(getS(offAirTimes))+'</td>';
					str += '<td align="center">'+vcmList[i].f_vcm_materialName+'</td>';
					str += '</tr>';
					flag = 0;
				}else{
					str += '<tr>';
					str += '<td align="center">'+getHMS(getS(airTimes))+'</td>';
					str += '<td align="center">'+getHMS(getS(airTimes)+time)+'</td>';
					str += '<td align="center">'+vcmList[i].f_vcm_materialName+'</td>';
					str += '</tr>';
					airTimes = getHMS(getS(airTimes)+time).split(":");
					if(i == (vcmList.length-1)){
						i=-1;
					}
				}
				if(flag == 0){
					i = vcmList.length-1;
				}
			}
			$('#carousel').append(str);
		}
	});
}

//通过时间s得到hms
function getHMS(times){
	 var time = parseInt(times);
	 var h = Math.floor(time / (60*60));
	 var m = Math.floor((time - 60*60*h) / 60);
	 var s = time - 60*60*h - m*60;
	 var hh = h+"";
	 var mm = m+"";
	 var ss = s+"";
	 if(h<10) hh = "0"+h;
	 if(m<10) mm = "0"+m;
	 if(s<10) ss = "0"+s;
	 return hh+":"+mm+":"+ss;
}
//通过时间hms得到s
function getS(airTimes){
	 return parseInt(airTimes[0])*60*60+parseInt(airTimes[1])*60+parseInt(airTimes[2]);
}

function back(){
	window.location.href="vchannel_programs.jsp";
}

if(offAirTime=="choose"){
	document.getElementById("carousel_one").style.display = "none";
	viewMateralChoose();
}else{
	document.getElementById("selectOffAirTime").style.display = "none";
	viewMateral();
}
function viewMateralChoose(){
	$.ajax({
		url:"../../virtual_channel/select_material.do?f_vc_id="+f_vc_id,
		success:function(data) {
			data = JSON.parse(data);
			var f_vc_airTime = data.f_vc_airTime;//00:00:00
			var f_vc_offAirTime = data.f_vc_offAirTime;//24:00:00
			var vcmList = data.virtualChannelMaterialVos;//可得到播放时长，时间秒数，素材信息
			var offAirTimes = f_vc_offAirTime.split(":");//结束时间
			var airTimes = f_vc_airTime.split(":");//开始时间
			var time = 0;//时长
			var str = '';
			var flag = 1;
			
			var vcList = data.interCutvirtualChannelVos;//插播节目列表
			var cbAirTime = null;//插播开始时间
			for(var i=0;i<vcmList.length;i++){
				time = vcmList[i].f_vcm_duration;
					for(var j=0;j<vcList.length;j++){
						cbAirTime = vcList[j].f_vc_airTime.split(":");//插播开始时间
						var vcmCBList = vcList[j].virtualChannelMaterialVos;//插播素材信息
						var cbTime = vcmCBList[0].f_vcm_duration;
						if(getS(cbAirTime)==getS(airTimes)){//正常插播
							for(var k=0;k<vcmCBList.length;k++){
								cbTime = vcmCBList[k].f_vcm_duration;
								str += '<tr>';
								str += '<td align="center"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnSelectOne(\''+getHMS(getS(cbAirTime)+cbTime)+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">选择</span></span></a></td>';
								str += '<td align="center">'+getHMS(getS(cbAirTime)+cbTime)+'</td>';
								str += '<td align="center">'+vcmCBList[k].f_vcm_materialName+'</td>';
								str += '</tr>';
								cbAirTime = getHMS(getS(cbAirTime)+cbTime).split(":");
								airTimes = cbAirTime;
							}
						}else if(getS(cbAirTime)>getS(airTimes)&&getS(cbAirTime)<(getS(airTimes)+time)){
							str += '<tr>';
							str += '<td align="center"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnSelectOne(\''+getHMS(getS(cbAirTime))+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">选择</span></span></a></td>';
							str += '<td align="center">'+getHMS(getS(cbAirTime))+'</td>';
							str += '<td align="center">'+vcmList[i].f_vcm_materialName+'</td>';
							str += '</tr>';
							for(var k=0;k<vcmCBList.length;k++){
								cbTime = vcmCBList[k].f_vcm_duration;
								str += '<tr>';
								str += '<td align="center"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnSelectOne(\''+getHMS(getS(cbAirTime)+cbTime)+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">选择</span></span></a></td>';
								str += '<td align="center">'+getHMS(getS(cbAirTime)+cbTime)+'</td>';
								str += '<td align="center">'+vcmCBList[k].f_vcm_materialName+'</td>';
								str += '</tr>';
								cbAirTime = getHMS(getS(cbAirTime)+cbTime).split(":");
								airTimes = cbAirTime;
							}
						}
					}
					
				if(getS(airTimes)+time>=getS(offAirTimes)){//大于结束时间
					str += '<tr>';
					str += '<td align="center"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnSelectOne(\''+getHMS(getS(offAirTimes))+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">选择</span></span></a></td>';
					str += '<td align="center">'+getHMS(getS(offAirTimes))+'</td>';
					str += '<td align="center">'+vcmList[i].f_vcm_materialName+'</td>';
					str += '</tr>';
					flag = 0;
				}else{
					str += '<tr>';
					str += '<td align="center"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnSelectOne(\''+getHMS(getS(airTimes)+time)+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">选择</span></span></a></td>';
					str += '<td align="center">'+getHMS(getS(airTimes)+time)+'</td>';
					str += '<td align="center">'+vcmList[i].f_vcm_materialName+'</td>';
					str += '</tr>';
					airTimes = getHMS(getS(airTimes)+time).split(":");
					if(i == (vcmList.length-1)){
						i=-1;
					}
				}
				if(flag == 0){
					i = vcmList.length-1;
				}
			}
			$('#selectOffAirTime').append(str);
		}
	});
}

function onClickBtnSelectOne(param){
	window.parent.offAirTime_ = param;
	window.parent.selectOfftime_close();
}
function back_one(){
	window.parent.selectOfftime_close();
}

function init(){
	window.location.href = 'vchannel_programs.jsp?f_vc_customid='+$('#f_vc_customid').val()+'&f_vc_customName='+$('#f_vc_customName').val();
}
</script>
</body>
</html>